/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DataMining;

import java.util.Vector;

/**
 *
 * @author Tuan
 */
public class Cluster {
    
    private Point centroid;
    
    private Vector points;
    
    public Cluster(Point cenPoint){
        this.points = new Vector();
        this.centroid = cenPoint;
    }
    
    public void reCalculateCentroid(){
        double totalX = 0;
        double totalY = 0;
        double totalZ = 0;
        for(int i = 0; i < this.points.size(); i++){
            Point point = (Point)this.points.elementAt(i);
            totalX += point.X;
            totalY += point.Y;
            totalZ += point.Z;            
        }
        int totalSize = this.points.size();
        this.setCentroid(new Point(totalX / totalSize, totalY/totalSize, totalZ/totalSize));          
    }
    
    public void assignNewPoint(Point p){
        this.points.addElement(p);
    }
    
    public void removePoint(Point p){
        this.points.removeElement(p);
    }

    /**
     * @return the centroid
     */
    public Point getCentroid() {
        return centroid;
    }

    /**
     * @param centroid the centroid to set
     */
    public void setCentroid(Point centroid) {
        this.centroid = centroid;
    }
    
    public void removeAllPoints(){
        this.points = new Vector();
    }
    
    public Vector getAllPoints(){
        return this.points;
    }
    
}
